<%--
  Created by IntelliJ IDEA.
  User: 申忠帅
  Date: 2021/4/7
  Time: 14:25
  To change this template use File | Settings | File Templates.
--%>
<%--商品分类管理--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<html>
<head>
    <title>商品分类管理</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - jqGird</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../../static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link rel="stylesheet" href="../../static/css/bootstrap.min.css">

    <!-- jqgrid-->
    <link href="../../static/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">

    <link href="../../static/css/animate.css" rel="stylesheet">
    <link href="../../static/css/style.css?v=4.1.0" rel="stylesheet">

</head>
<body>
<div class="ibox ">
    <p class="text-right">
        <h4 class="m-t">分类列表
        <p>
            <a href="comodity?opr=toadd" class="btn btn-primary">新增分类</a>
        </p>
</h4>
    </p>
    <div class="jqGrid_wrapper">
        <table id="table_list_1"></table>
        <div id="pager_list_1"></div>
    </div>
</div>

<%--    <table id="table_list_1" align="center"  class="table  table-hover table-bordered">--%>
<%--        <tr>--%>
<%--            <th>选择</th>--%>
<%--            <th>分类名称</th>--%>
<%--            <th>分类级别</th>--%>
<%--            <th>父类分级</th>--%>
<%--            <th>操作</th>--%>
<%--        </tr>--%>
<%--        <c:forEach items="${list}" var="item">--%>
<%--            <tr>--%>
<%--                <td>--%>
<%--                    <label type="${item.id}">--%>
<%--                        <input  type="radio" name="blankRadio" id="blankRadio1" value="option1" aria-label="">--%>
<%--                    </label>--%>
<%--                </td>--%>
<%--                <td>${item.name}</td>--%>
<%--                <td>--%>
<%--                    <c:if test="${item.type eq '0'}">一级</c:if>--%>
<%--                    <c:if test="${item.type eq '1'}">二级</c:if>--%>
<%--                    <c:if test="${item.type eq '2'}">三级</c:if>--%>
<%--                </td>--%>
<%--                <td>${item.parentId}</td>--%>
<%--                <td><a href=""class="btn btn-primary">删除</a></td>--%>
<%--            </tr>--%>
<%--        </c:forEach>--%>
<%--    </table>--%>

    <!-- 全局js -->
    <script src="../../static/js/jquery.min.js?v=2.1.4"></script>
    <script src="../../static/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- Peity -->
    <script src="../../static/js/plugins/peity/jquery.peity.min.js"></script>

    <!-- jqGrid -->
    <script src="../../static/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
    <script src="../../static/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

    <!-- 自定义js -->
    <script src="../../static/js/content.js?v=1.0.0"></script>
<script>
    $(document).ready(function () {
        $.jgrid.defaults.styleUI = 'Bootstrap';
        let users = "";
        //请求后台数据
        $.ajax({
            url: 'comodity?opr=list',
            method:'POST',
            data:'',
            datatype:'JSON',
            //让异步变成同步      代表同步
            async:false,
            success:function (d){
                users=$.parseJSON(d);
            }
        })
        $("#table_list_1").jqGrid({
            data: users,
            datatype: "local",
            height: 460,
            autowidth: true,
            shrinkToFit: true,
            rowNum: 20,
            rowList: [10, 20, 30],
            colNames: ['选择', '分类名称', '分类级别', '父类分级','操作'],
            colModel: [
                {
                    name: 'id',
                    index: 'id',
                    width: 40,

                },
                {
                    name: 'name',
                    index: 'name',
                    width: 90,
                },
                {
                    name: 'type',
                    index: 'type',
                    width: 90,
                },
                {
                    name: 'parentId',
                    index: 'parentId',
                    width: 90,
                },
                {
                    name: '',
                    index: '',
                    width: 90,
                }
            ],
            //jqgrid增 改 删 查 刷新
            pager: "#pager_list_1",
            //记录信息 ！！
            viewrecords: true,

            caption: "",
            add: true,
            edit: true,
            addtext: '增加',
            edittext: '修改',
            hidegrid: false,

        });
        $("#table_list_1 tr:not(:first) td:nth-child(5)").html(
            "<button type='button'class='btn btn-danger' onclick='delComod()'>删除</button>");
        $("#table_list_1 tr:not(:first) td:nth-child(1)").html(
            "<input type='radio' value=''>");
        function show(){
            $("#table_list_1").setSelection(1, true);
            $("#table_list_1 tr:not(:first) td:nth-child(5)").html(
                "<button type='button' class='btn btn-danger' onclick='delComod()'>删除</button>");
            $("#table_list_1 tr:not(:first) td:nth-child(1)").html(
                " <input type='radio'>");

        }
        // Add selection 默认选中第1行
        $("#table_list_1").setSelection(1, true);

        $("#last_pager_list_1,#prev_pager_list_1,#next_pager_list_1,#last_pager_list_1,#first_pager_list_1").click(function (){
            $("#table_list_1").setSelection(1, true);
            show();
        })

        $('input:radio').click(function(){
            var $radio = $(this);
            if ($radio.data('checked')){
                $radio.prop('checked', false);
                $radio.data('checked', false);
            } else {
                $radio.prop('checked', true);
                $radio.data('checked', true);
            }
        });
    });
    function delComod(){
        let fl = confirm("确认删除吗？");
        if (fl){
            setTimeout(function (){
                let id = $("#table_list_1").find("tr[aria-selected=true]").children(":first").attr('title');
                // console.log(id);
                //点击删除 跳进del选中id  进行删除
                location.href = "comodity?opr=del&id="+id;
            },50)
        }else {
            alert("操作取消！！！");
            return false;
        }
    }
</script>

</body>
</html>
